﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Data.SqlClient;
namespace FishbowlSynchronization
{
    //Store all Api from Fishbowl document
    public class Fishbowl
    {
        public static string listCustomerName(string key)
        {
            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><CustomerNameListRq></CustomerNameListRq></FbiMsgsRq></FbiXml>";
        }
        public static string CreateSaleOrder(SqlDataReader order, string key)
        {
            DataUtility utility = new DataUtility();

            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><SOSaveRq><SalesOrder>" +
                  "<Salesman>" + "admin" + "</Salesman>" +
                //Need to update order number 
                   "<Number>" + int.Parse(order["order_item_delivery_invoice_number"].ToString()) + "</Number>" +
                   "<Status>20 </Status>" +
                //"<Carrier></Carrier>" +
                  //"<FirstShipDate>"+ utility.FormatDate(order["order_item_delivery_date"].ToString()) +"</FirstShipDate>" +
                   "<CreatedDate>" + utility.FormatDate(order["order_date"].ToString()) + "</CreatedDate>" +
                   "<IssuedDate>" + utility.FormatDate(order["order_date"].ToString()) + "</IssuedDate>" +
                   "<TaxRateName>GST</TaxRateName>"+
                   "<CustomerContact>" + "Virgin Blue" + "</CustomerContact>" +
                   "<CustomerName>Virgin Blue</CustomerName>" +
                   "<FOB>" + "Origin" + "</FOB>" +
                   "<QuickBooksClassName></QuickBooksClassName>" +
                   "<LocationGroup>" + utility.LocationGroup(order["order_item_delivery_location"].ToString()) + "</LocationGroup>" +
                //"<LocationGroup>"+order["order_item_delivery_location"].ToString()+"</LocationGroup>" +
                   "<BillTo>" +
                   "<Name>" + "Virgin Blue" + "</Name>" +
                   "</BillTo>" +
                   "<Ship>" +
                   "<Name>Virgin Blue</Name>" +
                   "</Ship>" +
                   utility.returnOrderitems(int.Parse(order["order_item_delivery_invoice_number"].ToString())) +
                   "</SalesOrder><IssueFlag>true</IssueFlag></SOSaveRq></FbiMsgsRq></FbiXml>";
        }
        public static string CreateSaleOrder1(SqlDataReader order, string key)
        {
            DataUtility utility = new DataUtility();
            string InvoiceDate = order["deliverydate"].ToString();
            int DeliveryType = int.Parse(order["order_item_delivery_type"].ToString());
            int dayDelivery = DateTime.Parse(InvoiceDate.ToString()).Day;
            int monthDelivery = DateTime.Parse(InvoiceDate.ToString()).Month;
            int yearDelivery = DateTime.Parse(InvoiceDate.ToString()).Year;
            string locationGroup = order["order_item_delivery_location"].ToString();
            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><SOSaveRq><SalesOrder>" +
                 "<Salesman>" + "admin" + "</Salesman>" +
                //Need to update order number 
                   "<Number>" + utility.ContractInvNum(InvoiceDate, DeliveryType, locationGroup).ToString() + "</Number>" +
                //"<Number>" + order["deliverydate"].ToString() + "</Number>" +
                   "<Status>20 </Status>" +
                //"<Carrier></Carrier>" +
                //"<FirstShipDate></FirstShipDate>" +

                   "<CreatedDate>" + InvoiceDate + "</CreatedDate>" +
                   "<IssuedDate>" + InvoiceDate + "</IssuedDate>" +
                   "<TaxRateName>GST</TaxRateName>"+
                   "<CustomerContact>" + "Virgin Blue" + "</CustomerContact>" +
                   "<CustomerName>Virgin Blue</CustomerName>" +
                   "<FOB>" + "Origin" + "</FOB>" +
                   "<QuickBooksClassName></QuickBooksClassName>" +
                   "<LocationGroup>" + utility.LocationGroup(locationGroup) + "</LocationGroup>" +
                //"<LocationGroup>"+order["order_item_delivery_location"].ToString()+"</LocationGroup>" +
                   "<BillTo>" +
                   "<Name>" + "Virgin Blue" + "</Name>" +
                   "</BillTo>" +
                   "<Ship>" +
                   "<Name>Virgin Blue</Name>" +
                   "</Ship>" +
                   utility.returnOrderitems1(dayDelivery, monthDelivery, yearDelivery, DeliveryType, locationGroup) +
                   "</SalesOrder><IssueFlag>true</IssueFlag></SOSaveRq></FbiMsgsRq></FbiXml>";
        }
        
        public static string GetPick(string key, string SOnumber)
        {
            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><GetPickRq><PickNum>S" + SOnumber +
                   "</PickNum></GetPickRq></FbiMsgsRq></FbiXml>";
        }
        public static string SavePick(string key, string pick)
        {
            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><SavePickRq>" + pick +
                    "</SavePickRq></FbiMsgsRq></FbiXml>";
        }
        public static string SaveShip(string key, string SOnumber, string deliveryDate)
        {

            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><ShipRq><ShipDate>" + deliveryDate + "</ShipDate><OrderNums><OrderNum>S" + SOnumber + "</OrderNum></OrderNums>" +
                   "</ShipRq></FbiMsgsRq></FbiXml>";
        }
        public static string GetShipList(string key, string SOnumber, int locationGroupId)
        {
            /*return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><GetShipListRq><StartRecord>0</StartRecord>" +
                   "<RecordCount>10</RecordCount><OrderNumber>" + SOnumber + "</OrderNumber><LocationGroup>" + locationGroupId + "</LocationGroup>" +
                   "</GetShipListRq></FbiMsgsRq></FbiXml>";*/
            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><GetShipListRq><StartRecord>0</StartRecord>" +
                   "<RecordCount>10</RecordCount><OrderNumber>" + SOnumber + "</OrderNumber>" +
                   "</GetShipListRq></FbiMsgsRq></FbiXml>";
        }
        public static string GetShipment(string key, int shipId)
        {
            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><GetShipmentRq><ShipmentID>" + shipId + "</ShipmentID>" +
                   "</GetShipmentRq></FbiMsgsRq></FbiXml>";
        }
        public static string Export(string key, string exportType)
        {
            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><ExportRq><Type>" + exportType + "</Type></ExportRq></FbiMsgsRq></FbiXml>";
        }
        public static string ProductRQ(string key, string producNum)
        {
            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><ProductQueryRq><ProductNum>" + producNum +
                   "</ProductNum></ProductQueryRq></FbiMsgsRq></FbiXml>";
        }
        public static string LocationList(string key)
        {
            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><LocationListRq></LocationListRq></FbiMsgsRq></FbiXml>";
        }
        public static string GetSo(string key, string customerName)
        {
            return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><GetSOListRq><CustomerName>" + customerName + "</CustomerName><DateScheduledBegin>2012-06-06T00:00:00</DateScheduledBegin></GetSOListRq></FbiMsgsRq></FbiXml>";
            //return "<FbiXml><Ticket><Key>" + key + "</Key></Ticket><FbiMsgsRq><GetSOListRq><SONum>24</SONum></GetSOListRq></FbiMsgsRq></FbiXml>";
        }
    }
}
